import { http } from '@/utils/http'
export interface IFooItem {
  id: string
  name: string
}
interface RequestBase {
  url: string
  query?: Record<string, any>
  header?: {
    'content-type': 'application/json' | 'application/x-www-form-urlencoded'
    token: string
    [x: string]: any
  }
  hideErrorToast?: boolean
  hideRequestLoading?: boolean
}

interface RequestPost extends RequestBase {
  data?: Record<string, any>
}

/**
 *
 * @param data {RequestBase}
 * @returns
 */
export const getFoo = (data: RequestBase) => {
  return http({
    url: data.url,
    query: { ...data.query },
    method: 'GET',
    header: { 'content-type': 'application/x-www-form-urlencoded', ...data.header },
    hideErrorToast: data.hideErrorToast || false,
    hideRequestLoading: data.hideRequestLoading || false,
  })
}

/**
 * POST 请求
 * @param data {RequestPost}
 * @returns
 */
export const postFoo = (data: RequestPost) => {
  return http({
    url: data.url,
    data: { ...data.data },
    query: { ...data.query },
    method: 'POST',
    header: { 'content-type': 'application/x-www-form-urlencoded', ...data.header },
    hideErrorToast: data.hideErrorToast || false,
    hideRequestLoading: data.hideRequestLoading || false,
  })
}
